#include <iostream>
#include <cstdio>
#include<vector>
#include<Windows.h>
using namespace std;
// zdl:: 使用数组来存储
const int N = 1e3 + 10;
int id[N];

pair<int, int> s[N], e[N];
bool S[N], E[N];

int getM(int h1, int m1, int h2, int m2)
{
    int hr = h2 - h1;
    int mn = m2 - m1;

    return hr * 60 + mn + 1;
}
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int id;
        int cnt = 0, sum = 0;
        while (cin >> id)
        {
            // cout << "id" << ":" << id << endl;
            if (!id) break;
            char mod;
            int h, m;
            cin >> mod;
            scanf("%d:%d", &h, &m);
            if (mod == 'S' && !S[id]) s[id] = {h, m}, S[id] = E[id]= true, cnt++;
            else if (mod == 'E' && S[id])
            {
                sum += getM(s[id].first, s[id].second, h, m);
                S[id] = E[id] = false;
            }
            Sleep(2);
        }
        cout << cnt << " " << sum / (cnt == 0 ? 1 : cnt) << endl;
    }
    return 0;
}